// Copyright 2022 jeff.li. and/or its affiliates.

#include <iostream>

#include <gtest/gtest.h>
#include <tbir/runtime/half.h>

namespace tbir::runtime {

    TEST(Half, float_half_conversion) {
        { EXPECT_EQ(sizeof(Half), 2); }
        {
            float a = 2.2;
            Half h(a);
            float b = h;
            EXPECT_TRUE(std::abs(a - b) <= 0.01);
        }
        {
            int32_t a = 2;
            Half h((float(a)));
            int32_t b = std::floor(float(h));
            EXPECT_EQ(a, b);
        }
    }

    TEST(Half, Add) {
        Half h1 = 2.2;
        Half h2 = 1.1;
        Half h_result = h1 + h2;
        std::cout << "h1(" << h1 << ") + h2(" << h2 << ") = " << h_result << std::endl;
    }

    TEST(Half, Sub) {
        Half h1 = 2.2;
        Half h2 = 1.1;
        Half h_result = h1 - h2;
        std::cout << "h1(" << h1 << ") - h2(" << h2 << ") = " << h_result << std::endl;
    }

    TEST(Half, Mul) {
        Half h1 = 2.2;
        Half h2 = 1.1;
        Half h_result = h1 * h2;
        std::cout << "h1(" << h1 << ") * h2(" << h2 << ") = " << h_result << std::endl;
    }

    TEST(Half, Div) {
        Half h1 = 2.2;
        Half h2 = 1.1;
        Half h_result = h1 / h2;
        std::cout << "h1(" << h1 << ") / h2(" << h2 << ") = " << h_result << std::endl;
    }

}  // namespace tbir::runtime